package com.zx.practice01;

import java.lang.reflect.*;
import java.util.Arrays;

public class Dome01 {
    public static void main(String[] args) {
        String name = "com.zx.pojo.Person";
        Class clz = null;
        try {
            clz = Class.forName(name);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        System.out.println("类名为: " + clz.getSimpleName() + "在" + clz.getPackage() + "的包下");
        System.out.println("修饰符: " + Modifier.toString(clz.getModifiers()));
        System.out.println(clz.getSimpleName() + "继承于 " + clz.getSuperclass());
        System.out.println("接口信息：");
        Class[] interfaces = clz.getInterfaces();
        for (Class aClass : interfaces) {
            System.out.println("接口简称：" + aClass.getSimpleName());
            System.out.println("接口全名：" + aClass.getName());
        }
        System.out.println("---------------------------------");

        System.out.println("构造方法: ");
        Constructor[] cons = clz.getDeclaredConstructors();
        for (Constructor constructor : cons) {
            int length = constructor.getName().split("[.]").length;
            System.out.println(constructor.getName().split("[.]")[length-1] + "修饰符：" + Modifier.toString(constructor.getModifiers()) +
                    "参数类型" + Arrays.toString(constructor.getParameterTypes()));
        }
        System.out.println("---------------------------------");

        System.out.println("属性的获取");
        Field[] df = clz.getDeclaredFields();
        for (Field field : df) {
            System.out.println("属性名：" + field.getName());
            System.out.println("返回类型：" + field.getType().getSimpleName());
            System.out.println("修饰符：" + Modifier.toString(field.getModifiers()));
        }

        System.out.println("---------------------------------");
        System.out.println("方法的获取");
        Method[] md = clz.getDeclaredMethods();
        for (Method method : md) {
            System.out.println("修饰符：" + Modifier.toString(method.getModifiers()) + "返回值类型: "
                    + method.getReturnType().getSimpleName() +"方法名: " + method.getName());
            System.out.println("参数有" + Arrays.toString(method.getParameterTypes()));
            System.out.println("方法声明在：" + method.getDeclaringClass().getName() + "中");
            System.out.println("---------------------------------");

        }
    }
}
